var id = localStorage.getItem("id"); 
$(function(){
	
});
function replaceEmptyItem(arr){
    for(var i=0,len=arr.length;i<len;i++){
        if(!arr[i]|| arr[i]==''){
            arr.splice(i,1);
            len--;
             
        }
    }
};
//返回
function back(){
	//localStorage.removeItem("areaIds");
	var url=server_url+'/supplyManage/areaList.do';
	tl_config.last_url=url;
	tl_config.loadToWorkArea(url);
};
function submitCommit(){
	var areaId = null;
	$.ajax({
		url :server_url+'/rest/supplyManage/getSupplyAreaById.do?ran='+Math.random(),
		type:"post",
		data:{id:id},
		success:function(data){
			//console.log(data.data.supplyArea.data.areaId);
			areaId = data.data.supplyArea.data.areaId;
			var Id = areaId.split(",");
			replaceEmptyItem(Id);
			console.log(Id);
			for(var i=0;i<Id.length;i++){
				console.log(Id[i]);
				console.log($("#countyId").val());
				if(Id[i]==$("#countyId").val()){
					easyDialog.open({container:{header:'温馨提示',content:"该区域已经存在！请重新输入"},autoClose : 2000});
					return;
				}else{
					$.ajax({
						url:server_url+'/rest/supplyManage/insertSupplyArea.do?ran='+Math.random()+"&token="+token,
						type:"post",
						data:{
							id:id,
							areaId:areaId+$("#countyId").val()+","
						},
						success:function(data){
							if(data.retCode=="0000"){
								easyDialog.open({container:{header:'温馨提示',content:data.retMsg},autoClose : 2000});
								back();
							}
						}
					});
				}
			}
			
		}
	});
	
	
}